<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header('目录编辑')"></head>
<body>
<section class="content">
    <form id="form" class="form-horizontal" th:object="${content}">
        <input type="hidden" name="id" th:value="*{id}">
        <input type="hidden" name="bookCatalogId" th:value="*{bookCatalogId}">
        <div class="box-body">
            <div class="form-group">
                <div class="col-sm-12">
                    <textarea id="details" rowspan="10"></textarea>
                </div>
            </div>
        </div>
        <div class="box-footer" style="display: none">
            <button id="btn" type="button" class="btn btn-info pull-right" onclick="save()"></button>
        </div>
    </form>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:src="@{/demo/resources/adminlte/bower_components/ckeditor/ckeditor.js}"></script>
<script th:inline="javascript">

    $(function () {

        var content = [[${content}]]

        CKEDITOR.replace('details',
            {
                filebrowserImageUploadUrl: '/profile/ckUpload',
                toolbar:
                    [
                        //加粗     斜体，     下划线      穿过线      下标字        上标字
                        ['Bold','Italic','Underline','Strike','Subscript','Superscript'],
                        // 数字列表          实体列表            减小缩进    增大缩进
                        ['NumberedList','BulletedList','-','Outdent','Indent'],
                        //左对 齐             居中对齐          右对齐          两端对齐
                        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                        //超链接  取消超链接 锚点
                        ['Link','Unlink','Anchor'],
                        //图片    flash    表格       水平线            表情       特殊字符        分页符
                        ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
                        '/',
                        // 样式       格式      字体    字体大小
                        ['Styles','Format','Font','FontSize'],
                        //文本颜色     背景颜色
                        ['TextColor','BGColor'],
                        //全屏           显示区块
                        ['Maximize', 'ShowBlocks','-']
                    ]
            }
        );
        if (content!=null && content!=undefined){
            CKEDITOR.instances.details.setData(content.content);
        }
    })

    /**
     * 保存数据
     */
    function save() {
        var formData = new FormData($("#form")[0]);

        var details = CKEDITOR.instances.details.getData();
        formData.append("content", details)
        form('/sys/in/bookContent/save', formData, function (res) {
            window.parent.loaded(res.msg,res.code)
        }, function (error) {
            window.parent.loaded(error)
        })
    }
</script>
</body>